package com.xy.test;

import com.xy.bean.Person;
import com.xy.config.MainConfigPropertyValue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/4/8 19:36
 * @description
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MainConfigPropertyValue.class)
public class IOCTestPropertyValue {
    @Autowired
    private ApplicationContext context;

    @Test
    public void test01() {
        printBeans(context);
        System.out.println("+++++++++++");
        Person bean = context.getBean(Person.class);
        System.out.println("bean = " + bean);
        Environment environment = context.getEnvironment();
        System.out.println(environment.getProperty("person.name"));
        System.out.println(environment.getProperty("person.nickName"));
    }

    private void printBeans(ApplicationContext context) {
        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println("name = " + name);
        }
    }
}
